import useBackLogs from '@/hooks/pm/backLogs'
import useOwner from '@/hooks/pm/owner'
import PhoneLayout from '@/layout/index_phone'
import {to_phone_pmBaseInfo} from '@/libs/pageRedirect'
import {defineComponent, onMounted} from 'vue'
import TaskBlock, {TaskContent} from './components/taskBlock'

export default defineComponent({
  name: 'taskTodo',
  setup(props, ctx) {
    const {updateBackLogs, notHanderWorkList} = useBackLogs()
    const {udpateOwnerByPmId} = useOwner()

    onMounted(() => {
      updateBackLogs()
    })

    // 待办点击事件
    const todeskClick = item => {
      udpateOwnerByPmId({
        pmId: item.pmId,
        success(data) {
          to_phone_pmBaseInfo({
            defaultPmId: item.pmId,
            userDDId: data.pmUserDDId
          })
        }
      })
    }

    return () => (
      <PhoneLayout
        v-slots={{
          nav: () => (
            <div class='h-36 leading-36 px-16 shadow-card'>
              当前待办：{notHanderWorkList.value.length || 0}
            </div>
          )
        }}
      >
        <div class='w-full overflow-y-auto pb-36 pt-16'>
          {notHanderWorkList.value.map(item => (
            <div
              onClick={() => {
                todeskClick(item)
              }}
            >
              <TaskBlock title={item.createTime}>
                <TaskContent dataSource={item}></TaskContent>
              </TaskBlock>
            </div>
          ))}
        </div>
      </PhoneLayout>
    )
  }
})
